package cn.kai.controller;

import cn.kai.base.JsonResult;
import cn.kai.json.flow.FlowJson;
import cn.kai.process.flow.core.FlowChain;
import cn.kai.service.FlowService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 Author: cKnight
 Date: 2025/1/23
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/v1/flow")
public class FlowController {
    private final FlowService flowService;

    @PostMapping("/register")
    public JsonResult registerFlow(@RequestBody FlowJson flowJson){
        return JsonResult.buildSuccess(flowService.registerFlow(flowJson));
    }

    @GetMapping("/get")
    public JsonResult<Map<String, FlowChain>> getFlow(){
        return JsonResult.buildSuccess(flowService.getFlow());
    }

    @GetMapping("/execute")
    public JsonResult execute(@RequestParam String name){
        return JsonResult.buildSuccess(flowService.execute(name));
    }
}
